package com.web.products;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.domain.Products;
import com.service.ProductsService;
import com.util.AuthenticateHttpServlet;

/**
 * Servlet implementation class ProductHandler
 */
@WebServlet("/Product/Create")
public class ProductCreate extends AuthenticateHttpServlet {
	private static final long serialVersionUID = 1L;

	protected void post(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		try {
			String code = request.getParameter("code");
			String name = request.getParameter("name");
			float buyPrice = Float.parseFloat(request.getParameter("buyPrice"));
			float salesPrice = Float.parseFloat(request
					.getParameter("salesPrice"));
			String description = request.getParameter("description");
			ProductsService service = new ProductsService();
			service.insertProduct(new Products(code, name, buyPrice, salesPrice,
					description));
			request.getRequestDispatcher("/WEB-INF/Product/List").forward(request,
					response);
		} catch (NumberFormatException ex) {
			ex.printStackTrace();
		}
	}

}
